﻿Public Class MyGraphics

    Public Class Graphic

        Public Class Curve
            Private m_Color As Color
            Private m_strLabel As String
            Private m_adblXdata As Double()
            Private m_adblYdata As Double()

            Public Sub New(ByVal label As String, ByVal xData As Double(), ByVal yData As Double(), ByVal color As Color)
                m_strLabel = label
                m_adblXdata = xData
                m_adblYdata = yData
                m_Color = color
            End Sub

            Public ReadOnly Property Color() As Color
                Get
                    Return m_Color
                End Get
            End Property

            Public ReadOnly Property Label() As String
                Get
                    Return m_strLabel
                End Get
            End Property

            Public ReadOnly Property Xdata() As Double()
                Get
                    Return m_adblXdata
                End Get
            End Property

            Public ReadOnly Property Ydata() As Double()
                Get
                    Return m_adblYdata
                End Get
            End Property

        End Class

        Private m_aColorTable As Color() = {Color.Black, Color.Blue, Color.LimeGreen, Color.Red, Color.Gold, Color.Magenta, Color.Gray, Color.Cyan, Color.Orange, Color.Beige}
        Private m_strTitle As String
        Private m_strXAxisLabel As String
        Private m_strYAxisLabel As String
        Private m_objCurveList As New List(Of Curve)

        Public Sub New(ByVal title As String, ByVal xAxisLabel As String, ByVal yAxisLabel As String)
            m_strTitle = title
            m_strXAxisLabel = xAxisLabel
            m_strYAxisLabel = yAxisLabel
        End Sub

        Public Function AddLine(ByVal label As String, ByVal xData As Double(), ByVal yData As Double()) As Curve
            Dim intColorIndex As Integer = 0
            Dim objCurve As Curve = Nothing

            For intIndex As Integer = 0 To m_objCurveList.Count - 1
                If m_objCurveList.Item(intIndex).Label = label Then
                    objCurve = New Curve(String.Empty, xData, yData, m_objCurveList.Item(intIndex).Color)
                    Exit For
                Else
                    intColorIndex += 1
                End If
            Next
            If objCurve Is Nothing Then objCurve = New Curve(label, xData, yData, m_aColorTable(intColorIndex))

            m_objCurveList.Add(objCurve)

            Return objCurve
        End Function

        Public ReadOnly Property Count() As Integer
            Get
                Return m_objCurveList.Count
            End Get
        End Property

        Public ReadOnly Property Item(ByVal index As Integer) As Curve
            Get
                Return m_objCurveList.Item(index)
            End Get
        End Property

        Public ReadOnly Property Title() As String
            Get
                Return m_strTitle
            End Get
        End Property

        Public ReadOnly Property XAxisLabel() As String
            Get
                Return m_strXAxisLabel
            End Get
        End Property

        Public ReadOnly Property YAxisLabel() As String
            Get
                Return m_strYAxisLabel
            End Get
        End Property

    End Class

    Private m_objGraphicList As New List(Of Graphic)

    Public Function Add(ByVal title As String, ByVal xAxisLabel As String, ByVal yAxisLabel As String) As Graphic
        Dim objGraphic As New Graphic(title, xAxisLabel, yAxisLabel)

        m_objGraphicList.Add(objGraphic)

        Return objGraphic
    End Function

    Public Function Count() As Integer
        Return m_objGraphicList.Count
    End Function

    Public ReadOnly Property Item(ByVal index As Integer) As Graphic
        Get
            Return m_objGraphicList.Item(index)
        End Get
    End Property

End Class
